//
//  YBNewsTableViewCell.m
//  GoodBuy
//
//  Created by Cyber on 15/5/14.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "YBNewsTableViewCell.h"

@implementation YBNewsTableViewCell

-(void)dealloc {
    [_newsListModel release];
    [_titleLabel release];
    [_contentsLab release];
    [_commentLabel release];
    [_dateLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, [UIScreen mainScreen].bounds.size.width - 20, [UIScreen mainScreen].bounds.size.height/4/3+10)];
//    _titleLabel.backgroundColor = [UIColor yellowColor];
    _titleLabel.font = [UIFont systemFontOfSize:18];
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(10, _titleLabel.frame.origin.y + _titleLabel.frame.size.height, [UIScreen mainScreen].bounds.size.height/4/3*2 - 10, [UIScreen mainScreen].bounds.size.height/4/3*2-10)];
    _pictureView.contentMode = 2;
    _pictureView.layer.masksToBounds = YES;
    _pictureView.layer.cornerRadius = 20;
    [self.contentView addSubview:_pictureView];
    [_pictureView release];
    
    self.commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(_pictureView.frame.origin.x + 10 + _pictureView.frame.size.width, _titleLabel.frame.origin.y + _titleLabel.frame.size.height, 50, [UIScreen mainScreen].bounds.size.height/4/9)];
    _commentLabel.font = [UIFont systemFontOfSize:12];
    [_commentLabel setTextColor:[UIColor grayColor]];
//    _commentLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_commentLabel];
    
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-70, _commentLabel.frame.origin.y, 50, [UIScreen mainScreen].bounds.size.height/4/8)];
    _dateLabel.font = [UIFont systemFontOfSize:12];
    [_dateLabel setTextColor:[UIColor grayColor]];
//    _dateLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_dateLabel];
    
    self.contentsLab =
    [[UILabel alloc]initWithFrame:
     CGRectMake(_pictureView.frame.origin.x + _pictureView.frame.size.width + 10,
                _commentLabel.frame.origin.y + _commentLabel.frame.size.height,
                [UIScreen mainScreen].bounds.size.width - _commentLabel.frame.origin.x - 10,
                [UIScreen mainScreen].bounds.size.height/4 - _commentLabel.frame.origin.y - _commentLabel.frame.size.height)];
//    _contentsLab.backgroundColor = [UIColor yellowColor];
    _contentsLab.numberOfLines = 0;
    _contentsLab.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_contentsLab];
    [_contentsLab release];
    
}

- (void)awakeFromNib {
    // Initialization code
}

-(void)setNewsListModel:(YBNewsListModel *)newsListModel {
    _titleLabel.text = newsListModel.article_title;
    
    NSURL *pictureUrl = [NSURL URLWithString:newsListModel.article_pic];
    [_pictureView sd_setImageWithURL:pictureUrl placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    _commentLabel.text = [NSString stringWithFormat:@"评论:%@",newsListModel.article_comment ];
    _dateLabel.text = newsListModel.article_format_date;
    _contentsLab.text = newsListModel.article_filter_content;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
